<!DOCTYPE HTML>
<html>
<head>
    <include file="Public/head" />
<title>添加原料</title>
</head>
<body>
<div class="pd-20">

	<table class="table table-border table-bordered table-bg">

		<tbody>
			<tr class="text-c">
				<td class="text-r" style="background-color:#f5f5f5">生产计划单编号</td>
				<td class="text-l">
					<input type="text" name="purchasing_no" class="input-text" value="{$detail.purchasing_no}">
				</td>
				<td class="text-r" style="background-color:#f5f5f5">申请部门：</td>
				<td class="text-l">
					<input type="text"  class="input-text" name="section" value="{$detail.section}" >
				</td>	
			</tr>
			<tr class="text-c">				
				<td  class="text-r" style="background-color:#f5f5f5">产品名称：</td>
				<td class="text-l">
					<input type="text"  class="input-text" name="pro_name" value="{$detail.pro_name}" >
				</td>			
				<td class="text-r" style="background-color:#f5f5f5">产品数量：</td>
				<td class="text-l">
					<input type="text"  class="input-text" name="pro_num" value="{$detail.pro_num}" >
				</td>
			</tr>
			<tr class="text-c">	
				<td class="text-r" style="background-color:#f5f5f5">料号：</td>
				<td class="text-l">
					<input type="text"  class="input-text" name="source_no" value="{$detail.source_no}" >
				</td>
				<td class="text-r" style="background-color:#f5f5f5">产品编码：</td>
				<td class="text-l">
					<input type="text"  class="input-text" name="pro_no" value="{$detail.pro_no}" >
				</td>	
			</tr>
			<tr class="text-c">	
				<td class="text-r" style="background-color:#f5f5f5">单价：</td>
				<td class="text-l">
					<input type="text"  class="input-text" name="unit_price" value="{$detail.price}" >
				</td>		
				<td class="text-r" style="background-color:#f5f5f5"></td>
				<td class="text-l">
					
				</td>					
			</tr>
			
		</tbody>
	</table>
	
	<button onclick="admin_open('添加原料','{:U('goods',array('id'=>$detail['id']))}','','1000','600')" class="btn btn-primary">
	添加原料</button>
	
	<table class="table table-border table-bordered table-hover table-bg">
		<thead>
			<tr>
				<th scope="col" colspan="10">原料列表</th>
			</tr>
			<tr class="text-c">
				<th width="40">ID</th>
				<th width="40">生产计划单编号</th>

				<th width="40">原料编码</th>
				<th width="40">币制</th>
				<th width="40">单价($)</th>
				<th width="40">数量(个)</th>
				<th width="40">重量(kg)</th>
				<th width="40">原产国</th>
			</tr>
		</thead>
		<tbody>
			<volist name="list" id="vo">
			<tr class="text-c">
			 <input  name='gid' type="hidden" style="width:80px;" value="{$vo['id']}"/>
				<td>{$vo.id}</td>
				<td><span>{$vo.plan_receipts_id}</span></td>

				<td>{$vo.goods_no}</td>
				<td>{$vo.currency_name}</td>
				<td>
					 <input  name='price' type="input-text" style="width:80px;" value="{$vo['price']}"/>
				</td>
				<td>
					<input  name='declare_amount' type="input-text" style="width:80px" value="{$vo['declare_amount']}"/>
				</td>
				<td>
					<input  name='weight' type="input-text" style="width:80px" value="{$vo['weight']}"/>
				</td>
				<td>
					 <select name="country_code" class="form-control selects" style="width:130px">
                         <option value="">请选择</option>
                         <volist name="country" id="vcc">
                             <option value="{$vcc.country_code}" <if condition="$vcc['country_code'] == $vo['country_code']">selected</if>>{$vcc.country_name}</option>
                         </volist>
                     </select>
				</td>
	
			</tr>
			</volist>
		</tbody>
	</table>
	<input type="button" class="btn btn-primary radius mt" id="bedit" value="保存">
<div class="pages">
{$page}
</div>
</div>
<script type="text/javascript">
    $(function(){
		
		/*保存计划入库单数据*/
        $("#bedit").click(function(){
			var purchasing_no=$('input[name=purchasing_no]').val();
			var section=$('input[name=section]').val();
			var pro_name=$('input[name=pro_name]').val();
			var pro_num=$('input[name=pro_num]').val();
			var source_no=$('input[name=source_no]').val();
			var pro_no=$('input[name=pro_no]').val();
			var unit_price=$('input[name=unit_price]').val();
			
			var count=$('input[name=price]').length;
			var gid=$('input[name=gid]');
			var price=$('input[name=price]');
			var declare_amount=$('input[name=declare_amount]');
			var weight=$('input[name=weight]');
			var selects=$(".selects");
			
			var str='';
			for(var i=0;i<count;i++){
				if(price.eq(i).val()==0){
					layer.msg('单价不能为0');
					return false;
				}
				if(declare_amount.eq(i).val()==0){
					layer.msg('数量不能为0');
					return false;
				}
				if(weight.eq(i).val()==0){
					layer.msg('重量不能为0');
					return false;
				}
				var ss=selects.eq(i).find("option:selected").val();
				if(ss==''){
					layer.msg('请选择原产国');
					return false;
				}
				
				if(i==0){
					str=str+gid.eq(i).val()+":"+price.eq(i).val()+":"+declare_amount.eq(i).val()+":"+weight.eq(i).val()+":"+ss;
				}else{
					str=str+","+gid.eq(i).val()+":"+price.eq(i).val()+":"+declare_amount.eq(i).val()+":"+weight.eq(i).val()+":"+ss;
				}
			}
			
			$.ajax({
                type: 'POST',
                data: {
						id:{:I('id')},
						purchasing_no: purchasing_no,
						section: section,
						pro_name: pro_name,
						pro_num: pro_num,
						source_no: source_no,
						pro_no:pro_no,
						price:unit_price,
						strss:str
					  },
                url: "{:U('edt')}",
                success:function(data){
                    layer.msg(data.info,function(){
						if(data.status==0){
							return false;
						}else{
							self.window.location.href =self.window.location.href;
						}
						
					});
                }
            })
            
        });
		



    })
</script>
</body>
</html>
</html>